<?php

namespace frontend\behaviors;

use common\logics\RewardLogic;
use Yii;
use yii\base\Behavior;
use yii\web\User;

/**
 * after login behavior
 */
class AfterLoginBehavior extends Behavior {

    /**
     * {@inheritdoc}
     */
    public function events() {
        return [
            User::EVENT_AFTER_LOGIN => 'afterLogin',
        ];
    }

    /**
     * @param \yii\web\UserEvent $event
     * @return bool
     * @throws \yii\base\InvalidConfigException
     */
    public function afterLogin($event) {
        $user = $event->identity;
        if ($user && $user->getId()) {
            return RewardLogic::login($user->id);
        }
        return false;
    }

}